<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html">
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
</head>
<body erke-hide>
</body>
<script>
/**
 * @param {number[]} nums
 * @return {boolean}
 */
var containsNearbyDuplicate = function(nums, k) {
	var arr=[];
	var str=','+nums.join(',');
	for(var i=0;i<nums.length;i++){
		var index=str.indexOf(nums[i]);
		if(arrHas(arr,index)>=0){
			if(k==i-arrHas(arr,index)/2){
				console.log(true);
				return true;
			};
		};
		arr.push(index);
	};
	console.log(false);
	return false;
};
function arrHas(arrs,arr){
     for(var i=0;i<arrs.length;i++){
         if(arrs[i]==arr){
             return i;
         };
     };
    return -1;
};
var res=new containsNearbyDuplicate([1,2],2);
</script>
</html>